﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace MercuryFE
{
    public partial class ImageSelectorForm : Form
    {

        public string ImageName { get; set; }


        public ImageSelectorForm()
        {
            InitializeComponent();
        }

        private void ImageSelectorForm_Load(object sender, EventArgs e)
        {
            loadImages();
            this.ImageName = "";
        }


        private void loadImages()
        {
            //List<string> images = LauncherLib.getThemeImageList();
            string themePath = LauncherLib.getConfigItem("Theme Path");
            string[] validExtensions = new string[] { ".jpg", ".bmp", ".png", ".gif" };


            ilThemeImages = new ImageList();
            ilThemeImages.ImageSize = new Size(64, 64);
            lvThemeImages.Items.Clear();

            DirectoryInfo di = new DirectoryInfo(themePath);
            if (di.Exists)
            {
                int i = 0;
                foreach (FileInfo file in di.GetFiles())
                {
                    if (validExtensions.Contains(file.Extension)) {
                        Image img = Image.FromFile(file.FullName);
                        ilThemeImages.Images.Add(img);

                        ListViewItem item = new ListViewItem(file.Name);
                        item.ImageIndex = i++;
                        lvThemeImages.Items.Add(item);
                     }
                }
           }
           lvThemeImages.LargeImageList = ilThemeImages;
        }

        private void lvThemeImages_MouseClick(object sender, MouseEventArgs e)
        {
            if (lvThemeImages.SelectedItems.Count > 0)
            {
                this.ImageName = lvThemeImages.SelectedItems[0].Text;
                this.Close();
            }
            
        }
    }
}
